<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        车位添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}">
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}"></script>
    <!-- 引入ElementUI样式 -->
    <link rel="stylesheet" th:href="@{/css/index.css}">
    <style>
        .imgs{display: none;}
    </style>
</head>
<body>
<div id="app">
    <div class="x-body">
        <el-form : model="parking":rules="rules" ref="parkingFormRef" lable-width="120px" class="demo-ruleForm">
            <el-form-item label="所属小区" prop="communityName">
                <el-select v-model="paring.communityName" placeholder="--请选择小区名称--">
                    <el-option
                            v-for="item in findByCommunityName"
                            :key="item.index"
                            :label="item.communityName"
                            :value="item.communityName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="车位" prop="name">
                <el-input v-model="parking.name"></el-input>
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-radio-group v-model="parking.status">
                    <el-radio label="0">使用中</el-radio>
                    <el-radio label="1">闲置中</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="save()" style="text-align: center">保存</el-button>
                <el-button @click="clearAll()" style="text-align: center">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</div>

<!--    <form class="layui-form layui-form-pane" action="" id="add">-->
<!--        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">-->

<!--            <div class="layui-tab-content" >-->
<!--                <div class="layui-tab-item layui-show">-->
<!--                    <input type="hidden" name="id" value="">-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">-->
<!--                            <span class='x-red'>*</span>所属小区-->
<!--                        </label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <select name="community_id" id="community_id">-->
<!--                                <option value="0">-&#45;&#45;请选择-&#45;&#45;</option>-->
<!--                                <option value="1" >东湖小区</option>-->
<!--                                <option value="2" >金华万府</option>-->
<!--                            </select>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">-->
<!--                            <span class='x-red'>*</span>车位名称-->
<!--                        </label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="park_name" autocomplete="off" placeholder="空制在80个汉字，160个字符以内"-->
<!--                                   class="layui-input" value="">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">-->
<!--                            <span class='x-red'>*</span>状态-->
<!--                        </label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="radio" name="status" value="1" title="使用中" >-->
<!--                            <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon layui-anim-scaleSpring"></i>-->
<!--                                <div>使用中</div>-->
<!--                            </div>-->
<!--                            <input type="radio" name="status" value="0" title="闲置中" checked="checked">-->
<!--                            <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>-->
<!--                                <div>闲置中</div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-form-item">-->
<!--                        <button class="layui-btn" type="button" lay-filter="add" lay-submit="">-->
<!--                            保存-->
<!--                        </button>-->
<!--                    </div>-->
<!--                    &lt;!&ndash;</form>&ndash;&gt;-->
<!--                    <div style="height:100px;"></div>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
    </form>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/x-layui.js}" charset="utf-8"></script>
<script th:src="@{/js/jquery.js}" charset="utf-8"></script>
<!--导入Vue依赖包-->
<script th:src="@{/js/vue.js}" charset="UTF-8"></script>
<!-- 引入Element组件库 -->
<script th:src="@{/js/index.js}"></script>
<!--导入Axios依赖包-->
<script th:src="@{/js/axios.js}"></script>
<script type="text/javascript">
    var app = new Vue({
        el:"#app",
        data:{
            title:"添加车位",
            parking:{id:""},
            findByCommunityName:[],
            fileList:[],
            rules: {
                communityName: [
                    { required: true, message: '请选择所属小区名称', trigger: 'blur' }
                ],
                name:[
                    {required:true,message:'请输入车位的名称', trigger: 'blur'}
                ],
                status:[
                    { required: true, message: '请选择车位状态', trigger: 'change' }
                ]
            }
        },
        methods:{
            parkingFindAllByCommunityName(){
                axios.get("/parking/findByCommunityName").then((res)=>{
                    this.findByCommunityName = res.data.data;
                });
            },
            findById(){
                axios.get("/parking/findById?id="+this.parking.id).then((res)=>{
                   this.parking = res.data.data;
                   this.fileList.push({url:"http://localhost/estate"+this.community.thumbnail});
                });
            },
            //表达重置
            clearAll() {
                this.$refs.parkingFormRef.resetFields();
                if(this.fileList.length>0) {
                    this.handleRemove();
                }
            },
            save() {
                var method = "";
                if(this.parking.id != null){
                    method = "update"
                } else {
                    method = "add"
                }
                axios.post("/parking/"+method,this.parking).then((res)=>{
                    if(res.data.flag){
                        this.$message({
                            message:res.data.message,
                            type:'success'
                        });
                    }
                });
            },
            getQueryString(name){
                let reg = `(^|&)${name}=([^&]*)(&|$)`
                let r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
        },
        created:function(){
            layui.use(['element','layer','form'],function () {
                $ = layui.jquery;  //jquery
                lement = layui.element();  //面包导航
                layer = layui.layer;       //弹出层
                form = layui.form();
                okLoading.close($);
            })
            //获取父页面传递的参数，小区id
            this.parking.communityId = this.getQueryString("id");
            //根据小区ID获取小区对象，进行数据回显
            if(this.parking.communityId != null && this.parking.communityId != ''){
                this.title="修改房产";
                this.findById();
            }
            this.houseFindAllByCommunityName();
        }
    })
</script>
<!--<script type="text/javascript">-->
<!--    //实例化编辑器-->
<!--    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例-->
<!--    UE.getEditor('content',{initialFrameWidth:1000,initialFrameHeight:400,});-->
<!--</script>-->
<!--<script>-->
<!--    layui.use(['element','layer','form'], function(){-->
<!--        $ = layui.jquery;//jquery-->
<!--        lement = layui.element();//面包导航-->
<!--        layer = layui.layer;//弹出层-->
<!--        form = layui.form()-->
<!--        okLoading.close($);-->


<!--        //监听提交-->
<!--        form.on('submit(add)', function(data){-->
<!--            var park_name=$("input[name='park_name']").val();-->
<!--            var status=$("input[name='status']:checked").val();-->
<!--            var communidy=$('#communidy option:selected') .val();//所属栏目ID-->

<!--            if(communidy==""){-->
<!--                layer.msg('小区名称不能为空',{icon:5,time:2000});return false;-->
<!--            }-->
<!--            if(park_name==""){-->
<!--                layer.msg('车位名称不能为空',{icon:5,time:2000});return false;-->
<!--            }-->
<!--            if(status==""){-->
<!--                layer.msg('请选择状态！',{icon:5,time:2000});return false;-->
<!--            }-->
<!--            var data= data.field;-->
<!--            $.ajax({-->
<!--                type:"post",-->
<!--                url:"xxx",-->
<!--                data:data,-->
<!--                dataType:"json",-->
<!--                success:function(data){-->
<!--                    if(data.status==1){-->
<!--                        layer.msg(data.info, {icon: 6,time:2000},function () {-->
<!--                            window.parent.location.reload();-->
<!--                            var index = parent.layer.getFrameIndex(window.name);-->
<!--                            parent.layer.close(index);-->
<!--                        });-->
<!--                        return false;-->
<!--                    }-->
<!--                    else{-->
<!--                        layer.msg(data.info,{icon:5,time:2000});return false;-->
<!--                    }-->
<!--                }-->

<!--            });-->

<!--        });-->

<!--    })-->
<!--</script>-->
<!--&lt;!&ndash;栏目缩略图上传&ndash;&gt;-->
<!--<script>-->
<!--    function upload()-->
<!--    {-->
<!--        var formData = new FormData();-->
<!--        formData.append('images', $('#previewImg')[0].files[0]);-->
<!--        //console.log(formData);-->
<!--        layer.msg('图片上传中', {icon: 16});-->
<!--        $.ajax({-->
<!--            type:"post",-->
<!--            processData: false,-->
<!--            contentType: false,-->
<!--            url:"xxxx",-->
<!--            data:formData,-->
<!--            success:function(data){-->
<!--                if(data.status == 1){-->
<!--                    console.log(data.image_name);-->
<!--                    layer.closeAll('loading');-->
<!--                    //layer.msg(data.info,{icon:1,time:1000});-->
<!--                    $("#pimages").attr('src',data.image_name);-->
<!--                    $("#avatar").val(data.image_name);-->
<!--                    $(".imgs").show();-->
<!--                    return false;-->
<!--                }else{-->
<!--                    layer.msg(data.info,{icon:2,time:1000});-->
<!--                }-->
<!--            }-->
<!--        });-->
<!--    }-->
<!--</script>-->

</body>
</html>